package com.wondertek.liveroom;

import java.util.List;

import com.jasontools.data.ChatMessage;

import android.content.Context;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatMessageAdapter extends BaseAdapter{
	private List<ChatMessage> chatMsgList;
	private List<SpannableString> spanList;
	private LayoutInflater mInflater;
	private Context context = null;
	
	public ChatMessageAdapter(Context context, List<ChatMessage> chatMsgList){
		this.context = context;
		this.chatMsgList = chatMsgList;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return chatMsgList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return chatMsgList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (arg1 == null) {
			holder = new ViewHolder();
			arg1 = mInflater.inflate(R.layout.item_room_msg, null);
			holder.ivHeaderIcon = (ImageView) arg1.findViewById(R.id.person_header);
			holder.tvMsgContent = (TextView) arg1.findViewById(R.id.msg_content);
			holder.tvTime = (TextView) arg1.findViewById(R.id.msg_time);
			arg1.setTag(holder);
			
		} else {
			holder = (ViewHolder) arg1.getTag();
		}
		holder.tvMsgContent.setText(chatMsgList.get(arg0).getSpanChatContent());
		holder.tvTime.setText(chatMsgList.get(arg0).getChatTime());
//		holder.tvMsgContent.setText(spanList.get(arg0));
//		holder.tvTime.setText("19:19");
		return arg1;
	}
	
	private class ViewHolder {
		public ImageView ivHeaderIcon;
		public TextView tvMsgContent;
		public TextView tvTime;
	}

}
